package city_model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Calendar;


public class Station {
	private String id;
	private String name, fullName;
	private double latitude, longitude;
	private String junctionName;
	private Map<String, ArrayList<Calendar>> timeInformation;
	
public Station(String id, String name, String fullName)
{
	this.id =id;
	this.name = name;
	this.fullName = fullName;
	junctionName = null;
	timeInformation = new HashMap<String, ArrayList<Calendar>>();
}

public void setCoordinates(double latitude, double longitude)
{
	this.latitude = latitude;
	this.longitude = longitude;
}

public void setJunction(String junctionName)
{
	this.junctionName = junctionName;
}

public void setTimeInformation(String lineId, ArrayList<Calendar> times)
{
	timeInformation.put(lineId, times);
}

public boolean isTimeInformationSet(String lineId)
{
	for (Map.Entry<String,  ArrayList<Calendar>> entry :timeInformation.entrySet())
	{
		if(entry.getKey().equals(lineId))
		{
			return true;
		}
	}
	return false;
}

public ArrayList<Calendar> getTimeInformation(String lineId)
{
	for (Map.Entry<String,  ArrayList<Calendar>> entry :timeInformation.entrySet())
	{
		if(entry.getKey().equals(lineId))
		{
			return entry.getValue();
		}
	}
	return null;
}

public String getId()
{
	return id;
}

public String getName()
{
	return name;
}

public String getFullName()
{
	return fullName;
}

public String getJunctionName()
{
	return junctionName;
}

public double getLatitude()
{
	return latitude;
}
			
public double getLongitude()
{
	return longitude;
}

public int directDistanceTo(Station s)
{
	if (latitude == 0 || s.getLatitude() == 0 || longitude == 0 || s.getLongitude() == 0)
	{
		return -1;
	}
	double R = 6371;
	double dLat = (s.getLatitude() - latitude) * Math.PI / 180;
	double dLon = (s.getLongitude()-longitude) * Math.PI / 180;
	double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
		Math.cos(latitude * Math.PI / 180 ) * Math.cos(s.getLatitude() * Math.PI / 180 ) *
		Math.sin(dLon/2) * Math.sin(dLon/2);
	double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
	double d = R * c;
    return (int) Math.round(d*1000);
}

}
